<cfmodule template="../../tag/layout.cfm">
<cfscript>
	if( structKeyExists(rc, "ids") && listlen(ids) > 0){
		checkedids = rc.ids;
	}else{
		checkedids = 0;
	}
</cfscript>
<fieldset>
<legend>选择组织机构</legend>
<div id="tree"></div>
</fieldset>
</cfmodule>

<script type="application/javascript">
function getCheckedNames(){
    var nodes = $('#tree').tree('getChecked');
    var names = [];
    for(var i=0; i<nodes.length; i++){
        names.push(nodes[i].text);
    }
	return names.toString();
}	

function getCheckedIds(){
    var nodes = $('#tree').tree('getChecked');
    var ids = [];
    for(var i=0; i<nodes.length; i++){
        ids.push(nodes[i].id);
    }
    return ids.toString();
}
	
var submitForm = function($dialog,$orgids,$orgnames) {
	$orgids.val( getCheckedIds() );
	var str = '';
	if( getCheckedNames().length > 0 ){
		
		if( getCheckedNames().split(',').length > 3 ){
			str = '你选择了：'	 + getCheckedNames().split(',').slice(0,3) +	'等 ( ' + getCheckedNames().split(',').length	+' ) 个组织机构！';		
		}else{
			str = '你选择了：' + getCheckedNames()+	' ( ' + getCheckedNames().split(',').length	+' ) 个组织机构！';	
		}
				
	}else{
		str = '请选择组织机构！'
	}
	
	$orgnames.val( str );
	
	$dialog.dialog('destroy');
}	
	
var closeDialog = function($dialog) {
	$dialog.dialog('destroy');
}

$(function(){
	//列表操作
	var tree;
	
	tree = $("#tree").tree({
		url: '?action=organization.gettree',
		checkbox:true,
		onLoadSuccess : function(node, data) {
			var checkedids = '<cfoutput>#checkedids#</cfoutput>';
			for (var i=0;i<checkedids.split(',').length;i++)
			{
				var node = $('#tree').tree('find', checkedids.split(',')[i]);
				$('#tree').tree('check', node.target);	
			}
		}
	});

});
    
</script>